//
//  TYZSuspendTopPauseTableViewController.m
//  AVfoundationDemo
//
//  Created by TangBin on 2019/8/22.
//  Copyright © 2019 TangBin. All rights reserved.
//

#import "TYZSuspendTopPauseTableViewController.h"

@interface TYZSuspendTopPauseTableViewController ()

@end

@implementation TYZSuspendTopPauseTableViewController



- (void)initWithBaseTableView
{
    static CGFloat statusHeight;
    static CGRect bounds;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        bounds = [[UIScreen mainScreen] bounds];
        statusHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
    });
    CGFloat navBarHeight = self.navigationController.navigationBar.bounds.size.height;
    //    NSLog(@"statusHeight=%.2f; navBarHeight=%.2f", statusHeight, navBarHeight);
    CGRect frame = CGRectMake(0.0f, 0.0f, bounds.size.width, bounds.size.height - statusHeight - navBarHeight);
    if (self.isStyle)
    {
        self.baseTableView = [[TYZPageTableView alloc] initWithFrame:frame style:UITableViewStylePlain];
    }
    else
    {
        self.baseTableView = [[TYZPageTableView alloc] initWithFrame:frame style:UITableViewStyleGrouped];
    }
    //    _baseTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    // 右边的字母的颜色
    //    self.baseTableView.sectionIndexColor = UIColorFromRGB(0x555555);
    
    // ios11以后，setAutomaticallyAdjustsScrollViewInsets 禁用了，下面是替代方法
    /*
     当升级到iOS 11的时候,发现UIScrollView 有莫名其妙的偏移了 可是明明设置了
     automaticallyAdjustsScrollViewInsets
     这是因为iOS 11为UIScrollView 添加了新的属性contentInsetAdjustmentBehavior 这是一个枚举
     
     找到UIScrollViewContentInsetAdjustmentNever 从来不自动调整和automaticallyAdjustsScrollViewInsets = NO 是一个功效
     */
    if (@available(iOS 11.0, *))
    {
        self.baseTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        self.baseTableView.estimatedRowHeight = 0;
        self.baseTableView.estimatedSectionHeaderHeight = 0;
        self.baseTableView.estimatedSectionFooterHeight = 0;
    }
    self.baseTableView.delegate = self;
    self.baseTableView.dataSource = self;
    [self.view addSubview:self.baseTableView];
    
    
    
    
    // 2. 上拉加载更多(进入刷新状态就会调用doMoreRefreshData)
    MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(doMoreRefreshData)];
//    footer.ignoredScrollViewContentInsetBottom = ignoredScrollViewContentInsetBottom_;
    [footer setTitle:@"上拉加载更多数据" forState:MJRefreshStateIdle];
    [footer setTitle:@"松开加载更多数据" forState:MJRefreshStatePulling];
    [footer setTitle:@"正在加载中" forState:MJRefreshStateRefreshing];
    self.baseTableView.mj_footer = footer;
    
    [self hiddenFooterView:YES];
}

@end
